//
//  TableNumberManager.m
//  YIChuSeller
//
//  Created by 田小椿 on 2018/12/24.
//  Copyright © 2018年 xiangshengjun. All rights reserved.
//

#import "TableNumberManager.h"
#import "GXTableNumberModel.h"
@implementation TableNumberManager
+ (void)selectTableListWithStoreID:(NSString *)storeId success:(CompleteHandle)success fail:(CompleteHandle)fail{
    [SVProgressHUD show];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"YCS_DESL_SELECTDESK",
                @"parameters":@{
                        @"storeId":storeId,
                        }
                };
    [HttpHelper Post:@"ycs/Desk/Desk.do" parameters:jsonStr success:^(id responseObject) {
            if ([responseObject[@"cod"] isEqualToString:@"001"]) {
                [SVProgressHUD dismiss];
                NSDictionary * contentDic = responseObject[@"result"];
                if (![contentDic[@"desks"] count]) {
                    [SVProgressHUD showImage:nil status:@"无数据"];
                }else
                {
                    NSMutableArray * dataArray = [NSMutableArray array];
                    for (NSDictionary * dict in contentDic[@"desks"]) {
                        GXTableNumberModel * model = [GXTableNumberModel mj_objectWithKeyValues:dict];
                        [dataArray addObject:model];
                    }
                    success(dataArray);
                }
            }else{
                [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
            }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}

+ (void)addTableNumberWithStoreID:(NSString *)storeId deskName:(NSString *)deskName peopleNum:(NSString *)peopleNum success:(CompleteHandle)success fail:(CompleteHandle)fail
{
    [SVProgressHUD showWithStatus:@"添加中" maskType:SVProgressHUDMaskTypeClear];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"YCS_STORE_INSERTDESK",
                @"parameters":@{
                        @"storeId":storeId,
                        @"deskName":deskName,
                        @"peopleNum":peopleNum
                        }
                };
    [HttpHelper Post:@"ycs/Desk/Desk.do" parameters:jsonStr success:^(id responseObject) {
            if ([responseObject[@"cod"] isEqualToString:@"001"]) {
                [SVProgressHUD showSuccessWithStatus:@"添加成功"];
                success(responseObject);
            }else{
                [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
            }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}

+ (void)changeTableNumberWithDeId:(NSString *)deId deskName:(NSString *)deskName peopleNum:(NSString *)peopleNum success:(CompleteHandle)success fail:(CompleteHandle)fail
{
    [SVProgressHUD showWithStatus:@"更改中" maskType:SVProgressHUDMaskTypeClear];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"YCS_STORE_UPDATEDESK",
                @"parameters":@{
                        @"deId":deId,
                        @"deskName":deskName,
                        @"peopleNum":peopleNum
                        }
                };
    [HttpHelper Post:@"ycs/Desk/Desk.do" parameters:jsonStr success:^(id responseObject) {
            if ([responseObject[@"cod"] isEqualToString:@"001"]) {
                [SVProgressHUD showSuccessWithStatus:@"更改成功"];
                success(responseObject);
            }else{
                [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
            }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}

+ (void)deleteTableNumberWithDeId:(NSString *)deId success:(nonnull CompleteHandle)success fail:(nonnull CompleteHandle)fail
{
    [SVProgressHUD showWithStatus:@"删除中" maskType:SVProgressHUDMaskTypeClear];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"YCS_STORE_DELETEDESK",
                @"parameters":@{
                        @"deId":deId,
                        }
                };
    [HttpHelper Post:@"ycs/Desk/Desk.do" parameters:jsonStr success:^(id responseObject) {
        if (responseObject != nil) {
            if ([responseObject[@"cod"] isEqualToString:@"001"]) {
                [SVProgressHUD showSuccessWithStatus:@"删除成功"];
                success(responseObject);
            }else{
                [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
            }
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}
@end
